#ifndef __OFFLINE_H
#define __OFFLINE_H
#ifdef __cplusplus
extern "C"{
#endif

#include "rtthread.h"
#define STATE_ONLINE 0
#define STATE_OFFLINE 1

#define OFFLINE_EVENT_MAX_NUM 17

/* system protection uses event 0. */
#define SYSTEM_PROTECT NO_OFFLINE
#define OFFLINE_ERROR_LEVEL 0
#define OFFLINE_WARNING_LEVEL 1
#define APP_PROTECT_LEVEL 2

#define BEEP_DISABLE 0xFF


#define OFFLINE_ENABLE                       1
#define OFFLINE_DISABLE                      0

typedef void (*offline_t)(void);

typedef enum
{
    NO_OFFLINE = 0, /*!< system is normal */
    OFFLINE_SBUS,
    OFFLINE_CHASSIS_MOTOR1,
    OFFLINE_CHASSIS_MOTOR2,
    OFFLINE_CHASSIS_MOTOR3,
    OFFLINE_CHASSIS_MOTOR4,
    OFFLINE_GIMBAL_PITCH,
    OFFLINE_GIMBAL_YAW,
    OFFLINE_SHOOT_MOTOR_LEFT,
    OFFLINE_SHOOT_MOTOR_RIGHT,
    OFFLINE_SHOOT_MOTOR_RAMMER,
    OFFLINE_MINIPC_HEART,
    OFFLINE_REFEREE_SYSTEM,
    OFFLINE_BOARD_SMALL_YAW_1,
    OFFLINE_BOARD_SMALL_YAW_2,
    OFFLINE_BOARD_BIG_YAW,
    OFFLINE_BOARD_CHASSIS,
} offline_event;

typedef struct 
{
    offline_event event;
    uint8_t enable;
    uint8_t online_state;
    uint8_t last_state;
    uint8_t error_level;
    /* if offline event number is more than 1, beep_times equal minimum of all events. */
    /* max value is 0xFE */
    uint8_t beep_times;
    uint32_t last_time;
    uint32_t offline_time;
}offline_manage_obj;

extern offline_manage_obj offline_manage[OFFLINE_EVENT_MAX_NUM];

void offline_service_task_init(void);

void offline_event_init(offline_manage_obj obj);
void offline_event_time_update(offline_event event);
void offline_event_enable(offline_event event);
void offline_event_disable(offline_event event);

uint8_t get_system_status(void);

#ifdef __cplusplus
}
#endif

#endif // OFFLINE_H